//元素计数
/*给你一个整数数组 nums ，统计并返回在 nums 中同时至少具有一个严格较小元素和一个严格较大元素的元素数目。
1 <= nums.length <= 100
-10^5 <= nums[i] <= 10^5
*/
int compar(const void* q1, const void* q2) {
    return (*((int*)(q1)) - *((int*)(q2)));
}
int countElements(int* nums, int numsSize) {
    qsort(nums, numsSize, sizeof(int), compar);
    int i = 0;
    for (; i < numsSize - 1; i++) {
        if (nums[i] != nums[i + 1])
            break;
    }
    int j = numsSize - 1;
    for (; j > 0; j--) {
        if (nums[j] != nums[j - 1])
            break;
    }
    if (i < j) {
        return j - i - 1;
    } else {
        return 0;
    }
}

//给你一个下标从 0 开始、严格递增 的整数数组 nums 和一个正整数 diff 。如果满足下述全部条件，则三元组 (i, j, k) 就是一个 等差三元组 ：

/*i < j < k ，
nums[j] - nums[i] == diff 且
nums[k] - nums[j] == diff
返回不同 等差三元组 的数目。
3 <= nums.length <= 200
0 <= nums[i] <= 200
1 <= diff <= 50
nums 严格 递增*/
bool is_Trip(int* nums, int i, int* hash, int diff) {
    int temp = nums[i] + diff;
    for (int j = 0; j < 2; j++) {

        if (temp <= 200 && hash[temp] == 0)
            return false;
        else if (temp > 200)
            return false;
        temp += diff;
    }
    return true;
}
int arithmeticTriplets(int* nums, int numsSize, int diff) {
    int hash[201] = {0};
    int count = 0;

    for (int i = 0; i < numsSize; i++) {
        hash[nums[i]]++;
    }
    for (int i = 0; i < numsSize; i++) {
        if (is_Trip(nums, i, hash, diff))
            count++;
    }
    return count;
}


 